#ifndef __MODBUSP_H__
#define __MODBUSP_H__

#include "stdint.h"

typedef enum {
    MODBUSP_REG_R =0X0,
    MODBUSP_REG_W =0X1,
    MODBUSP_REGS_R =0X2,
    MODBUSP_REGS_W =0X3,
    MODBUSP_SYNC =0X4,
    // MODBUSP_SYNC_R =0XFE,
    // MODBUSP_SYNC_W =0XFF,
} modbusp_fc_e;

typedef struct {
    uint8_t addr;
    uint8_t fc;  /* @ref modbusp_fc_e */
    uint16_t crc;
    uint32_t data_len;
    uint8_t data[0];
} modbusp_mssg_t;

int modbusp_parse(const uint8_t *data, uint32_t len, modbusp_mssg_t *result);
int modbusp_pack(const modbusp_mssg_t *mssg, uint8_t *buff, uint32_t *len);

#endif /* __MODBUSP_H__ */

